package pixelradar.forge;

import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent.KeyInputEvent;
import pixelradar.Mw;

public class MwKeyHandler {
    public static KeyBinding keyRadar = new KeyBinding(I18n.format("key.open_radar"), 43, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyMapGui = new KeyBinding(I18n.format("key.mw_open_gui"), 50, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyNewMarker = new KeyBinding(I18n.format("key.mw_new_marker"), 210, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyMapMode = new KeyBinding(I18n.format("key.mw_next_map_mode"), 49, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyNextGroup = new KeyBinding(I18n.format("key.mw_next_marker_group"), 51, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyTeleport = new KeyBinding(I18n.format("key.mw_teleport"), 52, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyZoomIn = new KeyBinding(I18n.format("key.mw_zoom_in"), 201, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyZoomOut = new KeyBinding(I18n.format("key.mw_zoom_out"), 209, I18n.format("key.category.pixelradar"));
    public static KeyBinding keyUndergroundMode = new KeyBinding(I18n.format("key.mw_underground_mode"), 22, I18n.format("key.category.pixelradar"));
    public final KeyBinding[] keys;

    public MwKeyHandler() {
        this.keys = new KeyBinding[]{keyMapGui, keyNewMarker, keyMapMode, keyNextGroup, keyTeleport, keyZoomIn, keyZoomOut, keyUndergroundMode, keyRadar};

        for (KeyBinding key : this.keys) {
            if (key != null) {
                ClientRegistry.registerKeyBinding(key);
            }
        }

    }

    @SubscribeEvent
    public void keyEvent(KeyInputEvent event) {
        this.checkKeys();
    }

    private void checkKeys() {

        for (KeyBinding key : this.keys) {
            if (key != null && key.isPressed()) {
                Mw.getInstance().onKeyDown(key);
            }
        }

    }
}
